package cn.wolfcode.luowowo.flight.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;

@Getter
@Setter
public class PlaneTicket extends BaseDomain {
    public static final int PLANE_MODEL_SMALL = 0;
    public static final int PLANE_MODEL_MEDIUM = 1;
    public static final int PLANE_MODEL_LARGE = 2;

    private String company;             //航空公司
    private String flightnum;           //航班号
    private String source;              //出发地
    private String destination;         //目的地
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date takeoff;               //起飞时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date landing;               //到达时间
    private double price;               //价格
    private double fee;                 //机场建设费
    private String plane;               //机型
    private String airport;             //起飞机场
    private int model;                  //机型大小
    private Boolean hasmeal = false;    //有无餐食
    private int total;                  //剩余机票数

    public String getDepartport() {
        return airport.substring(0, 4);
    }

    public String getDestport() {
        return airport.substring(5);
    }

    public String getModel() {
        if (model == 0) {
            return "小";
        } else if (model == 1) {
            return "中";
        } else {
            return "大";
        }
    }

    public String getLast() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH小时mm分");
        return sdf.format(takeoff.getTime() - landing.getTime());
    }

    public String getMeal(){
        if (hasmeal==false){
            return "无餐食";
        }
        return "有餐食";
    }
}
